<template>
  <div>
    <el-checkbox-group

      v-model="roleIds"
    >
      <el-checkbox
        v-for="item in checkList"
        :key="item.id"
        :label="item.id"
      >{{ item.name }}</el-checkbox>

    </el-checkbox-group>

    <div style="margin-top: 20px; text-align: right">
      <el-button type="primary" @click="hSubmit">确定</el-button>
      <el-button @click="closeDialog">取消</el-button>
    </div>
  </div>
</template>

<script>
import { getRoles } from '@/api/setting'
import { getInfoProfileById } from '@/api/user'
import { assignRoles } from '@/api/employees'
export default {
  name: 'VueHrSecondAssignRole',
  props: {
    curId: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      roleIds: [],
      checkList: []
    }
  },
  created() {
    this.loadRoles()
  },
  methods: {
    async  hSubmit() {
      const res = await assignRoles({ id: this.curId, roleIds: this.roleIds })
      console.log(res)
      this.$emit('success')
    },
    async loadRoles() {
      const res = await getRoles({ page: 1, pagesize: 100 })
      const detail = await getInfoProfileById(this.curId)
      console.log(res, 'getRoles')
      console.log(detail, 'getInfoProfileById')
      this.checkList = res.data.rows
      this.roleIds = detail.data.roleIds
    },
    closeDialog() {
      this.$emit('close')
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
